package com.share.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class demo1_encoding extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //req、resp是服务器（tomcat）创建的
        //1、告诉服务器用什么编码，服务器默认用ISO-8859-8
//        resp.setCharacterEncoding("utf-8");
        //2、告诉客户端用什么编码
//        resp.setHeader("content-type","text/html;charset=utf-8");
//        resp.setHeader("Content-type", "application/json;charset=UTF-8");
        //3、由1和2合并
        System.out.println("demo1-threadName: " + Thread.currentThread().getName());
        resp.setContentType("text/html;charset=utf-8");


        PrintWriter out = resp.getWriter();
        out.println("你好sunxj");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
